package com.acp.result;

import jdk.nashorn.internal.objects.annotations.Constructor;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * All rights Reserved, Designed By 姑苏区政府大数据中心
 *
 * @version V1.0
 * @Title: null.java
 * @Package com.dci.controller.construction
 * @Description: 工具类
 * @author: 张星亮
 * @date: 2019/4/5
 * @Copyright: 2019 姑苏区政府大数据中心. All rights reserved.
 * 注意：本内容仅限于姑苏区政府大数据中心内部传阅，禁止外泄以及用于其他的商业目
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageResult {

    // 失败
    public static final int TYPE_RESULT_FAIL = 0;
    // 成功
    public static final int TYPE_RESULT_SUCCESS = 1;
    // 警告
    public static final int TYPE_RESULT_WARN = 2;
    // 提示信息
    public static final int TYPE_RESULT_INFO = 3;

    /**
     * 消息提示类型
     */
    private int type;

    /**
     * 提示代码
     */
    private int messageCode;

    /**
     *
     */
    private String message;

    /**
     * 数据
     */
    private List<?> data;

    /**
     * 总条数
     */
    private long count;

    private Map<String, Object> mapData = new HashMap<String, Object>();

    public PageResult(int type) {
        this.type = type;
    }

    /**
     * 返回成功
     * @param list
     * @param count
     * @return PageResult 类型
     */
    public static PageResult success(List<?> list, Long count) {
        PageResult result = new PageResult(TYPE_RESULT_SUCCESS);
        result.data = list;
        result.messageCode = 200;
        result.message = "加载成功!";
        result.count = count;
        return result;
    }

    public static PageResult fail(int msg) {
        PageResult pageResult = new PageResult(TYPE_RESULT_FAIL);
        pageResult.messageCode = msg;
        return pageResult;
    }

    public Map<String, Object> getMapData() {
        return mapData;
    }

    public void setMapData(Map<String, Object> mapData) {
        this.mapData = mapData;
    }

}
